package com.xiaoshuidi.cloud.module.member.enums;

import cn.hutool.core.lang.Assert;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum StatusEnum {
    NOT_EFFECTIVE(1, "未生效"),
    EFFECTIVE(2, "已生效"),
    EXPIRED(3, "已失效");
    private Integer code;
    private String name;

    public static String getNameByCode(Integer code) {
        StatusEnum statusEnum = Arrays.stream(StatusEnum.values()).filter(p -> p.code.intValue() == code.intValue()).findFirst().orElse(null);
        Assert.isTrue(statusEnum != null, "StatusEnum:{}不存在", code);
        return statusEnum.getName();
    }
}
